package com.pzh.guli.service.edu.service.imp;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pzh.guli.service.edu.listener.ExcelSubjectListener;
import com.pzh.guli.service.edu.pojo.Subject;
import com.pzh.guli.service.edu.mapper.SubjectMapper;
import com.pzh.guli.service.edu.pojo.excel.ExcelSubject;
import com.pzh.guli.service.edu.pojo.vo.SubjectVo;
import com.pzh.guli.service.edu.service.ISubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.List;

/**
 * <p>
 * 课程科目 服务实现类
 * </p>
 *
 * @author xzh
 * @since 2022-05-11
 */
@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements ISubjectService {
    @Resource
    private SubjectMapper subjectMapper;
    @Override
    public void batchImport(InputStream inputStream) {
        EasyExcel.read(inputStream, ExcelSubject.class,new ExcelSubjectListener(subjectMapper))
                .excelType(ExcelTypeEnum.XLS)
                .sheet().doRead();
    }

    @Override
    public List<SubjectVo> nestList() {
        return baseMapper.selectNestedList("0");
    }
     //获取一级目录
    @Override
    public  List<Subject> getOneLevel() {
        QueryWrapper<Subject> queryWrapper=new QueryWrapper();
        queryWrapper.eq("parent_id",0);
        return subjectMapper.selectList(queryWrapper);
    }
   //获取二级目录
    @Override
    public List<Subject> getTwoLevel() {
        return subjectMapper.getTwoList();
    }
}
